/**
 * 
 */
package cn.haona.game.simb.wap.actions.login;

import java.util.Date;

import cn.haona.game.simb.object.bio.User;
import cn.haona.game.simb.object.department.HAB;
import cn.haona.game.simb.object.god.MainManager;
import cn.haona.game.simb.object.god.cache.Cache;
import cn.haona.game.simb.servlet.SessionHn;
import cn.haona.game.simb.servlet.SessionHnManager;
import cn.haona.game.simb.wap.AppDefine;
import cn.haona.game.simb.wap.actions.ActionSimbParent;
import cn.haona.game.simb.wap.servlet.WebDefine;

/**
 * 登录Action
 * 
 * @author Administrator
 * 
 */
public class LoginAction extends ActionSimbParent {

	private String loginname;
	private String password;

	private String notice;


	public String loginValidate() {
		boolean isEmpty = false;
		if (loginname == null || password == null) {
			isEmpty = true;
		}

		if (loginname.equals("") || password.equals("")) {
			isEmpty = true;
		}

		// 如果参数不为空
		if (!isEmpty) {
			HAB hab = MainManager.getInstance().getEntityManager().getHab();
			User user = hab.checkExistUser(loginname, password);
			if (user != null) {
				//得到SessionHn
				SessionHn sessionHn = SessionHnManager.getSessionHn();
				//放入SessionHn
				sessionHn.addElement(SessionHn.KEY_USERBEAN, user);
				//存入缓存
				SessionHnManager.saveSessionHn(sessionHn);
			} else {
				notice = "incorrect input";
				return "inputerror";
			}
		}
		// 参数为空
		else {
			notice = "name or password empty!";
			return "empty";
		}
		return SUCCESS;
	}

	public String getLoginname() {
		return loginname;
	}

	public void setLoginname(String loginname) {
		this.loginname = loginname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNotice() {
		return notice;
	}

	public void setNotice(String notice) {
		this.notice = notice;
	}

}
